﻿@layout SettingsLayout
@page "/admin/settings/"
@inject HttpClient _http
@inject IStringLocalizer<Resource> _localizer
<PageTitle Title="@_localizer["basic-settings"]" />

<h1 class="section-title">@_localizer["basic-settings"]</h1>
<div class="section-content -half">
    @if (Blog != null)
    {
        <EditForm model="@Blog" OnValidSubmit="Save">
            <DataAnnotationsValidator />
            <ValidationSummary />
            <div class="form-item">
                <label class="form-label">@_localizer["default-cover"]</label>
                <button class="settings-cover" type="button" onclick="">
                    <img class="settings-cover-img" id="defaultCover" src="@Constants.DefaultCover" alt="@_localizer["default-cover"]">
                </button>
            </div>
            <div class="form-item">
                <label class="form-label">@_localizer["title"]</label>
                <input type="text" class="form-control" @bind="Blog.Title" name="title" />
            </div>
            <div class="form-item">
                <label class="form-label">@_localizer["description"]</label>
                <textarea class="form-control" cols="30" rows="5" @bind="Blog.Description" name="description"></textarea>
            </div>
            <div class="form-item">
                <button type="submit" class="btn btn-blogifier px-5">@_localizer["save"]</button>
            </div>
        </EditForm>
    }
</div>
<ToasterComponent @ref="Toaster" />

@code {
    protected Blog Blog { get; set; }
    protected ToasterComponent Toaster;

    protected override async Task OnInitializedAsync()
    {
        Blog = await _http.GetFromJsonAsync<Blog>("api/blog");
    }

    protected async Task Save()
    {
        Toaster.Toast(await _http.PutAsJsonAsync<Blog>("api/blog", Blog));
    }
}
